﻿package mortal.game.scene3D.display3d.blood
{
    import __AS3__.vec.*;
    import baseEngine.basic.*;
    import baseEngine.core.*;
    import flash.events.*;
    import flash.geom.*;
    import frEngine.*;
    import frEngine.event.*;

    public class Blood3D extends Pivot3D
    {
        private var _targetVector:Vector.<Number>;
        private var _ix:int;
        private var _iy:int;
        private var _iz:int;
        private var _iw:int;
        private var _isShowing:Boolean = false;
        protected var _rate:Number = 1;
        private var _updataPos:Boolean = false;
        private static var _temp0:Vector3D = new Vector3D();

        public function Blood3D()
        {
            super("");
            this.enabledPool = false;
            FrEventDispatcher.instance.proxyAddEventListener(this, Engine3dEventName.VISIBLE_CHANGE_EVENT, this.visibleChangeHander);
            return;
        }// end function

        override public function dispose(param1:Boolean = true) : void
        {
            throw new Error("请覆盖dispose方法");
        }// end function

        public function set bloodRate(param1:Number) : void
        {
            if (this._rate == param1)
            {
                return;
            }
            var _loc_2:int = 1;
            param1 = 1;
            var _loc_2:int = 0;
            param1 = 0;
            this._rate = param1;
            return;
        }// end function

        public function reInit(param1:Vector.<Number>) : void
        {
            this._targetVector = param1;
            this._ix = param1.length;
            this._iy = this._ix + 1;
            this._iz = this._ix + 2;
            this._iw = this._ix + 3;
            this._updataPos = true;
            this._targetVector[this._ix] = 0;
            this._targetVector[this._iy] = 0;
            this._targetVector[this._iz] = 0;
            this._targetVector[this._iw] = this._rate;
            this._isShowing = true;
            if (this._targetVector.length > 400)
            {
                throw new Error("超出范围,最多可创建200个血条");
            }
            return;
        }// end function

        override public function update(param1:int = 0) : void
        {
            var _loc_3:Vector3D = null;
            if (!this._targetVector)
            {
                return;
            }
            var _loc_2:* = this._targetVector[this._iw];
            if (this._isShowing && this._rate != _loc_2)
            {
                this._targetVector[this._iw] = _loc_2 + (this._rate - _loc_2) * 0.125;
            }
            if (this._updataPos)
            {
                _loc_3 = this.getPosition(false, _temp0);
                this._targetVector[this._ix] = _loc_3.x;
                this._targetVector[this._iy] = int(_loc_3.y / 2) * 2;
                this._targetVector[this._iz] = _loc_3.z;
                this._updataPos = false;
            }
            return;
        }// end function

        public function show() : void
        {
            if (this.parent)
            {
                var _loc_1:* = this._rate;
                this._targetVector[this._iw] = this._rate;
            }
            this._isShowing = true;
            return;
        }// end function

        override public function addedToScene(param1:Scene3D) : Boolean
        {
            var _loc_2:* = super.addedToScene(param1);
            if (this._isShowing && _loc_2)
            {
                var _loc_3:* = this._rate;
                this._targetVector[this._iw] = this._rate;
            }
            return _loc_2;
        }// end function

        public function hide() : void
        {
            var _loc_1:int = -1;
            this._targetVector[this._iw] = -1;
            this._isShowing = false;
            return;
        }// end function

        private function visibleChangeHander(event:Event) : void
        {
            if (this.visible)
            {
                this.show();
            }
            else
            {
                this.hide();
            }
            return;
        }// end function

        override public function updateChildrenTransform(param1:int = 0) : void
        {
            this.worldTransformChanged = true;
            this._updataPos = true;
            return;
        }// end function

        override public function updateTransforms(param1:Boolean, param2:Boolean, param3:int = 0) : void
        {
            this.worldTransformChanged = true;
            var _loc_4:* = this.getPosition(false, _temp0);
            var _loc_5:* = _loc_4.x;
            this._targetVector[this._ix] = _loc_4.x;
            var _loc_5:* = int(_loc_4.y / 2) * 2;
            this._targetVector[this._iy] = int(_loc_4.y / 2) * 2;
            var _loc_5:* = _loc_4.z;
            this._targetVector[this._iz] = _loc_4.z;
            this._updataPos = false;
            return;
        }// end function

    }
}
